package jm.algorithm.greedy;

import java.util.Arrays;
import java.util.Comparator;

/**
 * @Description 零钱兑换
 * @date 2022/5/20 15:13
 */
public class CoinChange {

    public static void main(String[] args) {
        Integer[] faces = {25, 10, 5, 1};
        Arrays.sort(faces, (Integer f1, Integer f2) -> f2 - f1);
        int money = 41;
        int coins = 0;
        int i = 0;
        while (i < faces.length){
            if (money < faces[i]){ // 只有无法选定当前硬币是才切换下一个小的硬币，
                i++;
                continue;
            }
            money -= faces[i];
            coins++;
            System.out.println(faces[i]);
        }
    }
}
